#include <cctype>
#include <map>
#include <iostream>
#include <fstream>
#include <sstream>
#include <strstream>
#include <string>

using namespace std;

bool my_isaplha(string &word){
    for(auto it=word.begin();it!=word.end();it++){
        if(!isalpha(*it)){
            return false;
        }
    }
    return true;
}

class Dict{
public:
    Dict(){
        cout<<"--- Dict() ---"<<endl;
    }

    void put(string &key){
        ++dict[key];
    }

    int get(string &key){
        return dict[key];
    }

    void read(string & filename){
        ifstream ifs(filename);
        string word;
        while(ifs>>word){
            if(my_isaplha(word))
                    put(word);
        }
    }

    void store(string & filename){
        ofstream ofs(filename);
        for(auto it=dict.begin();it!=dict.end();it++){
            ofs<<(*it).first<<" "<<(*it).second<<endl;
        }
        cout<<"--- Store Done ---"<<endl;
    }

private:
    map<string,int> dict;

};

void test(){
    Dict *dict=new Dict();
    string readFile="./The_Holy_Bible.txt";
    dict->read(readFile);
    string findWord="you";
    cout<<"--- "<<findWord<<" freq: "<<dict->get(findWord)<<" ---"<<endl;
    
    string storeFile="./Map_Bible.txt";
    dict->store(storeFile);
}

int main()
{
 test();
 return 0;
}

